package com.xhf.kl;

import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xhf.kl.utils.DensityUtils;
import com.xhf.kl.utils.StatusBarCompat;

public class HomeActivity extends AppCompatActivity {
    private FrameLayout framelayout;
    private ImageView iv_set;
    private AlertDialog alertDialog;
    private TextView tv_test,tv_saoyisao,tv_fenxian,tv_shouji_no,tv_phone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);// 无标题
        setContentView(R.layout.activity_home);
        StatusBarCompat.translucentStatusBar(this);//沉浸状态栏
        initview();
        LinearLayout.LayoutParams linearParams =(LinearLayout.LayoutParams) framelayout.getLayoutParams();
        linearParams.width = DensityUtils.getScreenWidth(HomeActivity.this)-DensityUtils.dp2px(HomeActivity.this,120*2);
        linearParams.height = DensityUtils.getScreenWidth(HomeActivity.this)-DensityUtils.dp2px(HomeActivity.this,120*2);
        framelayout.setLayoutParams(linearParams); //动态设置二维码大小
        iv_set.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDialog();
            }
        });

    }

    private void initview(){
        framelayout= (FrameLayout) findViewById(R.id.framelayout);
        iv_set= (ImageView) findViewById(R.id.iv_set);

        tv_test= (TextView) findViewById(R.id.tv_test);
        tv_test.setTextSize(TypedValue.COMPLEX_UNIT_SP,DensityUtils.px2sp(HomeActivity.this,72));
        tv_saoyisao= (TextView) findViewById(R.id.tv_saoyisao);
        tv_saoyisao.setTextSize(TypedValue.COMPLEX_UNIT_SP,DensityUtils.px2sp(HomeActivity.this,48));
        tv_fenxian= (TextView) findViewById(R.id.tv_fenxian);
        tv_fenxian.setTextSize(TypedValue.COMPLEX_UNIT_SP,DensityUtils.px2sp(HomeActivity.this,48));
        tv_shouji_no= (TextView) findViewById(R.id.tv_shouji_no);
        tv_shouji_no.setTextSize(TypedValue.COMPLEX_UNIT_SP,DensityUtils.px2sp(HomeActivity.this,40));
        tv_phone= (TextView) findViewById(R.id.tv_phone);
        tv_phone.setTextSize(TypedValue.COMPLEX_UNIT_SP,DensityUtils.px2sp(HomeActivity.this,48));
    }


    private void showDialog() {
        alertDialog = new AlertDialog.Builder(HomeActivity.this, R.style.MessageDialog).create();
        alertDialog.show();
        alertDialog.getWindow().clearFlags(
                WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
//        alertDialog.setCanceledOnTouchOutside(false);
        Window window = alertDialog.getWindow();
        window.setContentView(R.layout.dialog_set);
        window.setGravity(Gravity.CENTER);  //此处可以设置dialog显示的位置
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = DensityUtils.getScreenWidth(HomeActivity.this)/4*3;
        lp.height = lp.WRAP_CONTENT;
        window.setAttributes(lp);
        EditText et_psw= (EditText) window.findViewById(R.id.et_psw);
        TextView tv_sure= (TextView) window.findViewById(R.id.tv_sure);
        TextView tv_cancle= (TextView) window.findViewById(R.id.tv_cancle);
        TextView tv_title= (TextView) window.findViewById(R.id.tv_title);
        tv_title.setTextSize(TypedValue.COMPLEX_UNIT_SP,DensityUtils.px2sp(HomeActivity.this,60));
        tv_sure.setTextSize(TypedValue.COMPLEX_UNIT_SP,DensityUtils.px2sp(HomeActivity.this,48));
        tv_cancle.setTextSize(TypedValue.COMPLEX_UNIT_SP,DensityUtils.px2sp(HomeActivity.this,48));
        tv_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
            }
        });
        tv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
            }
        });
    }
}
